package com.ymatou.iapi.godmch.testcase;

import java.util.ArrayList;
import java.util.List;

import org.json.JSONException;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.godmch.parameter.createIndepMchBean;
import com.ymatou.iapi.godmch.parameter.getConfigBean;
import com.ymatou.iapi.godmch.service.createIndepMchCall;
import com.ymatou.iapi.godmch.service.getConfigCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.shenqi.GodmchManageCallService;
import com.ymttest.database.model.country_info;
import com.ymttest.database.model.mch_info;
import com.ymttest.database.model.godmch.mch_config;
import com.ymttest.database.model.godmch.mch_configExample;
import com.ymttest.database.sqlwapper.godmch.country_infoWapper;
import com.ymttest.database.sqlwapper.godmch.mch_configWapper;
import com.ymttest.database.sqlwapper.godmch.mch_infoWapper;
/**
*获取商户配置
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_getConfig{
	private static getConfigBean bean;
	private static getConfigCall call;
	
	createIndepMchBean createBean;
	mch_infoWapper infoWapper;
	country_infoWapper country_infoWapper;
	
	mch_configWapper configWapper;
	mch_configExample configExample;
	
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("获取商户配置");
	}

	@Before
	public void caseUp() {
		bean=new getConfigBean();
		call=new getConfigCall();
		createBean=new  createIndepMchBean();
		infoWapper=new mch_infoWapper();
		country_infoWapper=new country_infoWapper();
		
		configWapper=new mch_configWapper();
		configExample=new mch_configExample();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(call.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	
	private void check_verify() throws JSONException, InterruptedException
	{
		Logger.verifyEquals("200", call.getStatusCode1(), "验证status");
		Logger.verifyEquals("请求成功", call.getMessage(), "验证Message");
		
		createIndepMchBean result=call.getResult();
		List<Integer> mchIds=new ArrayList<Integer>();
		mchIds.add(call.getMchId());
		mch_info  info=infoWapper.selectbyMchIds(mchIds).get(0);
		
		configExample.createCriteria().andMchIdEqualTo(call.getMchId());
	    mch_config  config=configWapper.selectByExample(configExample).get(0);
	    
		Logger.verifyEquals(true, info.getMchId()>0, "验证数据库mch_info新增一条数据");
		Logger.verifyEquals(true, config.getMchId()>0, "验证数据库mch_config新增一条数据");
//		//mch_info
//		Logger.verifyEquals(0, info.getAgent(), "验证数据库mch_info中的agent");
//		Logger.verifyEquals(1, info.getChannels(), "验证数据库mch_info中的Channels");
//		Logger.verifyEquals(bean.getAgentInvite()==true?1:0, info.getVip(), "验证数据库mch_info中的Vip(如果代理可以邀请代理商，vip=1)");
//		country_info country_info=country_infoWapper.selectByPrimaryKey(bean.getCountry());
//		Logger.verifyEquals(country_info.getCurrency(), info.getCurrency(), "验证数据库mch_info中的Currency");
//		Logger.verifyEquals(bean.getCountry(), info.getCountry(), "验证数据库mch_info中的Country");
//
//		Logger.verifyEquals(0, info.getState(), "验证数据库mch_info中的State");
//		
//		Logger.verifyEquals(bean.getMchShareType(), info.getMchShareType(), "验证数据库mch_info中的MchShareType");
//		Logger.verifyEquals(2, info.getPayMode(), "验证数据库mch_info中的paymode");
//		Logger.verifyEquals(2, info.getMchType(), "验证数据库mch_info中的MchType");
		//mch_config
		Logger.verifyEquals(result.getLogo(), config.getLogo(), "验证数据库mch_config中的Logo");
		Logger.verifyEquals(result.getTitle(), config.getTitle(), "验证数据库mch_config中的Title");
		Logger.verifyEquals(result.getHomeBanner(), config.getHomeBanner(), "验证数据库mch_config中的HomeBanner");
		if(createBean.getPcDomain()==null)
			Logger.verifyEquals(result.getDomain(), config.getPcDomain(), "验证数据库mch_config中的PcDomain");
		else
		   Logger.verifyEquals(result.getPcDomain(), config.getPcDomain(), "验证数据库mch_config中的PcDomain");
		
		if(createBean.getH5Domain()==null)
			Logger.verifyEquals(result.getDomain(), config.getH5Domain(), "验证数据库mch_config中的H5Domain");
		else
		  Logger.verifyEquals(result.getH5Domain(), config.getH5Domain(), "验证数据库mch_config中的H5Domain");
		
		if(createBean.getAppDomain()==null)
			Logger.verifyEquals(result.getDomain(), config.getAppDomain(), "验证数据库mch_config中的AppDomain");
		else
		   Logger.verifyEquals(result.getAppDomain(), config.getAppDomain(), "验证数据库mch_config中的AppDomain");
		
		if(createBean.getS1Domian()==null)
			Logger.verifyEquals(result.getDomain(), config.getS1Domain(), "验证数据库mch_config中的S1Domian");
		else
		   Logger.verifyEquals(result.getS1Domian(), config.getS1Domain(), "验证数据库mch_config中的S1Domian");
		
		Logger.verifyEquals(result.getWxAppId(), config.getWxAppId(), "验证数据库mch_config中的WxAppId");
		Logger.verifyEquals(result.getWxSecret(), config.getWxSecret(), "验证数据库mch_config中的WxSecret");
		Logger.verifyEquals(result.getWxAppIdBuyer(), config.getWxAppIdBuyer(), "验证数据库mch_config中的WxAppIdBuyer");
		Logger.verifyEquals(result.getWxSecretBuyer(), config.getWxSecretBuyer(), "验证数据库mch_config中的WxSecretBuyer");
		Logger.verifyEquals(result.getWxAppIdPc(), config.getWxAppIdPc(), "验证数据库mch_config中的WxAppIdPc");
		Logger.verifyEquals(result.getWxSecretPc(), config.getWxSecretPc(), "验证数据库mch_config中的WxSecretPc");
		Logger.verifyEquals(result.getWxAppIdApp(), config.getWxAppIdApp(), "验证数据库mch_config中的WxAppIdApp");
		Logger.verifyEquals(result.getWxSecretApp(), config.getWxSecretApp(), "验证数据库mch_config中的WxSecretApp");
		Logger.verifyEquals(result.getWxAppIdH5(), config.getWxAppIdH5(), "验证数据库mch_config中的WxAppIdH5");
		Logger.verifyEquals(result.getWxSecretH5(), config.getWxSecretH5(), "验证数据库mch_config中的WxSecretH5");
		
		Logger.verifyEquals(result.getAgentPublish(), config.getAgentPuhlish(), "验证数据库mch_config中的AgentPuhlish 代理商能否发布商品");
		Logger.verifyEquals(result.getAgentInvite(), config.getAgentInvite(), "验证数据库mch_config中的AgentInvite代理商能否邀请代理");
		Logger.verifyEquals(result.getAgentInheritShareType(), config.getAgentInheritShareType(), "验证数据库mch_config中的AgentInheritShareType代理商是否继承渠道商店铺买家端呈现形式");
		
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getConfig_001() {
		Logger.start(true,"正例-获取商户配置-mchId不为空,domain为空");
		try {
			
			createBean=GodmchManageCallService.InitCreateIndepMchBean();
			createIndepMchCall createCall=GodmchManageCallService.CreateIndepMchCall(createBean);
			bean.setMchId(createCall.getmchId());
			call.setData(bean);
			call.callService();			
			check_verify();
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getConfig_002() {
		Logger.start(true,"正例-获取商户配置-mchId为空,domain不为空");
		try {
			
			createBean=GodmchManageCallService.InitCreateIndepMchBean();
			createIndepMchCall createCall=GodmchManageCallService.CreateIndepMchCall(createBean);
			bean.setDomain(createBean.getDomain());
			call.setData(bean);
			call.callService();			
			check_verify();
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getConfig_003() {
		Logger.start(true,"正例-获取商户配置-mchId不为空,domain不为空");
		try {

			createBean=GodmchManageCallService.InitCreateIndepMchBean();
			createIndepMchCall createCall=GodmchManageCallService.CreateIndepMchCall(createBean);
			bean.setMchId(createCall.getmchId());
			bean.setDomain(createBean.getDomain());
			call.setData(bean);
			call.callService();			
			check_verify();
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getConfig_003_1() {
		Logger.start(true,"正例-获取商户配置-mchId不为空,domain不为空,但是mchId 与 domain 不一致");
		try {

			createBean=GodmchManageCallService.InitCreateIndepMchBean();
			createIndepMchCall createCall=GodmchManageCallService.CreateIndepMchCall(createBean);
			bean.setMchId(createCall.getmchId());
			bean.setDomain(createBean.getDomain()+1);
			call.setData(bean);
			call.callService();			
			check_verify();
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getConfig_004() {
		Logger.start(true,"正例-获取商户配置-mchId为空,domain为空");
		try {
			bean.setMchId(null);
			bean.setDomain(null);
			call.setData(bean);
			call.callService();			
			
			Logger.verifyEquals("5000", call.getStatusCode1(), "验证status");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getConfig_005() {
		Logger.start(true,"正例-获取商户配置-mchId不存在");
		try {
			
			bean.setMchId(9999);
			call.setData(bean);
			call.callService();		
			
			Logger.verifyEquals("200", call.getStatusCode1(), "验证status");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getConfig_006() {
		Logger.start(true,"正例-获取商户配置-domain不存在");
		try {

			bean.setDomain("9999");
			call.setData(bean);
			call.callService();		
			
			Logger.verifyEquals("200", call.getStatusCode1(), "验证status");		
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}